package com.building.common;

import lombok.Data;

import static com.building.common.ResultCode.ERROR;
import static com.building.common.ResultCode.SUCCESS;

/**
 * @Description
 * @Author konglz
 * @Data 2023/2/28 16:08
 */
@Data
public class JsonResult<T> {
    private Integer code;

    private String message;

    private T data;

    JsonResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static JsonResult sucess() {
        return new JsonResult(SUCCESS.getCode(), SUCCESS.getMessage(), null);
    }

    public static JsonResult sucess(Object data) {
        return new JsonResult(SUCCESS.getCode(), SUCCESS.getMessage(), data);
    }

    public static JsonResult sucess(int code, String message) {
        return new JsonResult(code, message, null);
    }

    public static JsonResult sucess(String message) {
        return new JsonResult(SUCCESS.getCode(), message, null);
    }

    public static JsonResult error(Object data) {
        return new JsonResult(ERROR.getCode(), ERROR.getMessage(), data);
    }

    public static JsonResult error(int code, String message) {
        return new JsonResult(code, message, null);
    }

    public static JsonResult error(String message) {
        return new JsonResult(ERROR.getCode(), message, null);
    }
}
